package top.lixunda.ecommerce.server.auth.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Xumda
 * @version time:2019/11/21 13:30
 * <p>
 * 拦截所有request请求
 */
@SuppressWarnings("Duplicates")
@Slf4j
public class RequestInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //设置requestAttributes可继承，子线程可以获取
        log.debug("设置requestAttributes可继承，子线程可以获取");
        RequestContextHolder.setRequestAttributes(RequestContextHolder.getRequestAttributes(), true);
        return super.preHandle(request, response, handler);
    }
}
